<?php
class MY_Controller extends CI_Controller
{
    public function __construct(){
        parent::__construct();
        header("Content-type: text/html; charset=utf-8");
        $this->load->model('users_model');
        $this->load->model('bbs_user_model');
        $this->load->model('account_model');
        $this->load->model('bbs_behavior_model');
        $this->load->model('bbs_notice_model');
        $this->load->model('bbs_account_model');
        $this->load->library('Crypt');
        $this->load->library('Aes');
        
        $this->load->driver('cache');//导入缓存驱动类
        $this->memcached = $this->cache->memcached;//全局memcached句柄
        
        $request_url = array("/mplat.html","news");
        foreach ($request_url as $val){
            if($val == $_SERVER['REQUEST_URI'] || strpos($_SERVER['REQUEST_URI'],$val)){
                finance_redirect_url($_SERVER['REQUEST_URI']);
                break;
            }
        }
        
        $this->remote_url = array(
            "sms_url" => "http://api.tan66.com/index.php?r=sms/send",
            "query_url" => "http://api.tan66.com/index.php?r=plat/query",
            "recieve_url" => "http://api.tan66.com/index.php?r=user/recieve",
        );
        
        //网站全局配置
        $this->settings->load('config');
        $this->web_config = setting('config');
        //加载奖励配置
        $this->settings->load('award');
        $this->config_award = setting('award');
        //社区消息类型
        $this->settings->load('bbs_event');
        $this->bbs_event = setting('bbs_event');
        
        //加载任务配置
        $this->settings->load('task');
        $this->config_task = setting('task');
        //URL来路
        $HTTP_REFERER = @$_SERVER['HTTP_REFERER'];
        $this->redirectLink = $HTTP_REFERER? $HTTP_REFERER:site_url(); 
        //判断登录状态
	$this->userinfo = $this->session->userdata('userinfo');

        //var_dump($this->session);exit;
        if($this->userinfo){
            $this->assign('uinfo',$this->userinfo);
        }

        if($this->userinfo){
            //获取用户社区账户
            $this->bbs_userinfo = $this->bbs_user_model->get_users(intval($this->userinfo['user_id']));
            $user = $this->db->query("select salt from tan_users where user_id = ".$this->userinfo['user_id'])->row_array();
            if(!$this->bbs_userinfo){//老用户创建社区数据
                //创建社区用户表
                $this->bbs_user_model->insert_bbs_user(array("user_id"=>$this->userinfo['user_id'],"salt"=>$user['salt'],"reg_time"=>  time(),"group_id"=>1,"create_time"=>  time()));
                //创建社区用户账户表
                $this->bbs_user_model->insert_bbs_account(array("user_id"=>$this->userinfo['user_id']));
                //创建社区个人统计表
                $this->bbs_user_model->insert_bbs_count(array("user_id"=>$this->userinfo['user_id']));
                
                //添加个人动态
                //$this->insert_behavior(array('user_id'=>$this->userinfo['user_id'],"operator_id"=>0,"event_type"=>"event_reg"));
                //系统通知
                $this->insert_notice(array('user_id'=>0,"operator_id"=>0,"recieve_id"=>$this->userinfo['user_id'],"event_type"=>"event_reg","type"=>"system","content"=>"欢迎来到弹溜溜社区大家庭！！"));
                $this->bbs_userinfo = $this->bbs_user_model->get_users(intval($this->userinfo['user_id']));
            }
            //获取用户信息
            if($this->bbs_userinfo){
                $this->bbs_userinfo['account'] = $this->db->query("select * from tan_account where user_id = ".$this->userinfo['user_id']." order by id desc limit 1")->row_array();
                $this->bbs_userinfo['account']['balance_format'] = number_format($this->bbs_userinfo['account']['balance']);
                $this->bbs_userinfo['account']['balance_zhu'] = number_format(intval($this->bbs_userinfo['account']['balance']/10000));
                //验证是否是已认证用户
                $this->bbs_userinfo['is_verified'] = ($this->db->query("select * from tan_bbs_user_verified where user_id = ".$this->userinfo['user_id']." and status = 1 ")->num_rows()) ? 1 : 0;
            }
            $bbs_user_info = $this->bbs_userinfo;
            $bbs_user_info['head_img'] = strstr($bbs_user_info['head_img'], "http://") ? $bbs_user_info['head_img'] : "http://www.tan66.com".$bbs_user_info['head_img'];
            
            //用户禁止访问权限
            $this->users_no_access = explode(",", $this->bbs_userinfo['no_access']);
            //用户组禁止访问权限
            $group_no_access = $this->bbs_user_model->get_user_group(array("id"=>$this->bbs_userinfo['group_id']));
            $this->group_no_access = explode(",", $group_no_access['no_access']);
            
            
            //私信未读
            $letter_message_count = $this->db->select("*")->from("bbs_user_dialog_message")->where(array("sender_to_id"=>$this->bbs_userinfo['user_id'],"is_read"=>0,"is_show"=>0))->order_by("id desc")->get()->num_rows();
            //平台未读
            $finance_message_count = $this->db->select("*")->from("users_award_notice")->where(array("user_id"=>$this->bbs_userinfo['user_id'],"is_del"=>0,"is_see"=>0))->order_by("id desc")->get()->num_rows();
            //系统通知未读
            $system_message_count = $this->db->select("*")->from("bbs_notice")->where("(recieve_id = ".$this->bbs_userinfo['user_id']." or recieve_id = 0) and is_read not like '%".$this->bbs_userinfo['user_id']."%'  and type = 'system'")->order_by("id desc")->get()->num_rows();
            //文章消息未读
            $where_in_art = "'event_add_article_care','event_collect_article','event_reply_article','event_like_article','event_comment_article','event_reward_article'";
            $artcle_message_count = $this->db->select("*")->from("bbs_notice")->where("(recieve_id = ".$this->bbs_userinfo['user_id']." or recieve_id = 0) and is_read not like '%".$this->bbs_userinfo['user_id']."%' and type = 'article' and event_type in ($where_in_art)")->order_by("id desc")->get()->num_rows();
            //问答消息未读
            $where_in_wenda = "'event_comment_wenda','event_comment_wenda_care','event_reply_wenda','event_like_answer','event_care_answer','event_best_answer','event_add_wenda_care'";
            $wenda_message_count = $this->db->select("*")->from("bbs_notice")->where("(recieve_id = ".$this->bbs_userinfo['user_id']." or recieve_id = 0) and is_read not like '%".$this->bbs_userinfo['user_id']."%' and type = 'wenda' and event_type in ($where_in_wenda)")->order_by("id desc")->get()->num_rows();
            //获取未读消息
            $message_count = array(
                //私信
                'letter_message_count'=> $letter_message_count > 99 ? "99+" : $letter_message_count,
                'finance_message_count'=> $finance_message_count > 99 ? "99+" : $finance_message_count,
                'system_message_count'=> $system_message_count > 99 ? "99+" : $system_message_count,
                'artcle_message_count'=> $artcle_message_count > 99 ? "99+" : $artcle_message_count,
                'wenda_message_count'=> $wenda_message_count > 99 ? "99+" : $wenda_message_count,
                'total_count' =>  ($letter_message_count + $finance_message_count + $system_message_count + $artcle_message_count + $wenda_message_count) > 99 ? "99+" : ($letter_message_count + $finance_message_count + $system_message_count + $artcle_message_count+ $wenda_message_count)
            );
            $this->assign("message_count", $message_count);
            
        }
        $this->assign("alogin", $this->userinfo ? json_encode(array("uuid"=>  encrypt_user_id($this->bbs_userinfo['user_id']),"unick"=>$this->bbs_userinfo['nickname'],"isline"=>1,"uname"=>$this->bbs_userinfo['username'])) : json_encode(array("uuid"=>0,"unick"=>"","isline"=>0,"uname"=>"")));
        //验证用户是否有权限操作
        if($_POST && isset($_POST["action"]) && trim($_POST["action"])){
            if(in_array($_POST["action"], $this->users_no_access) || in_array($_POST["action"], $this->group_no_access)){
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1000;
                $mess['errorMsg'] = "对不起，您还没有此权限";
                echo JSON($mess);exit;
            }
        }
        $this->session_id = session_id();
        //社区文章类别板块
        $this->settings->load('forummenu');
        $this->forummenu = setting("forummenu");
         //当前模块
	$this->module = $this->uri->segment(1) ? $this->uri->segment(1) : 'index';
        //当前页面
	$this->action = $this->uri->segment(2)? $this->uri->segment(2) : 'index';
        
        
        $this->ip = $this->input->ip_address();
        $this->assign('bbs_user_info',$bbs_user_info ? $bbs_user_info : "");
        $this->assign('module',$this->module);
        $this->assign('action',$this->action);
        $this->assign('SESSIONID', $this->session_id);
        
        //网站配置相关
        $this->website_config = $this->db->query("select * from tan_website_config where id = 1 order by id desc limit 1")->row_array();
        
        $this->assign("website_config", $this->website_config);
        
        $this->footer_data();
        
        $this->assign("style_dir", STYLE_DIR);//全局样式路径
    }
    
    public function assign($key,$val) {   
        $this->cismarty->assign($key,$val);   
    }   
  
    public function display($html) {   
        $this->cismarty->display($html);   
    }
    //添加个人动态
    public function insert_behavior($data){
        $this->bbs_behavior_model->insert($data);
    }
    //添加系统消息
    public function insert_notice($data){
        $this->bbs_notice_model->insert($data);
    }
    //批量添加系统通知
    public function insert_notice_batch($datas){
        $this->db->insert_batch("bbs_notice",$datas);
    }
    //友情链接
    private function footer_data(){
        //合作机构
        $partners = $this->db->select('*')->from('partners')->where(array('is_show'=>1))->order_by("sort", "asc")->get()->result_array(); 
        $this->assign("partners", $partners);
         //总获取溜溜币
        $total_amount = $this->db->select('SUM(total) total_amount')->from('account')->get()->row_array();
        $total_amount = number_format($total_amount['total_amount']);
        $this->assign("total_amount", $total_amount);
        //总投资金额
        $total_invest_amount = $this->db->select('SUM(amount) total_amount')->from('plat_invest_list')->get()->row_array();
        $total_invest_amount = number_format(intval($total_invest_amount['total_amount']+244828480));
        $this->assign("total_invest_amount", $total_invest_amount);
        //总人数
        $total_users = $this->db->query('select count(*) total from tan_users order by user_id desc')->row_array();
        $total_users = $total_users['total'];
        $total_users = number_format($total_users - 2500);
        $this->assign("total_users", $total_users);
        
    }
    
    //设置时间进度1
    public function set_time($time){
        $curent_time = time();
        $_second = $curent_time - $time;
        $_time = $_second / 60;//分钟
        if($_time < 1){
            return $_second."秒前";
        }
        
        if($_time > 1 && $_time < 60){
            return intval($_time)."分前";
        }
        
        if($_time > 60 && $_time < 1440){
            return intval($_time / 60) ."小时前";
        }
        
        if($_time > 1440 && $_time < 7200){
            return intval($_time / 1440) ."天前";
        }
        
        if($_time > 7200){
            return date("Y-m-d H:i",$time);
        }
    }
    
    //设置时间进度2
    public function set_time_two($time){
        $curent_time = time();
        $_second = $curent_time - $time;
        $_time = $_second / 60;//分钟
        if($_time < 1){
            return $_second."秒前";
        }
        
        if($_time > 1 && $_time < 60){
            return intval($_time)."分前";
        }
        
        if($_time > 60 && $_time < 1440){
            return intval($_time / 60) ."小时前";
        }
        
        if($_time > 1440){
            return date("Y-m-d H:i",$time);
        }
    }
    
    public function set_time_three($time){
        $curent_time = time();
        $_second = $curent_time - $time;
        $_time = $_second / 60;//分钟
        if($_time < 1){
            return $_second."秒前";
        }
        
        if($_time > 1 && $_time < 60){
            return intval($_time)."分前";
        }
        
        if($_time > 60 && $_time < 1440){
            return intval($_time / 60) ."小时前";
        }
        
        if($_time > 1440){
            return intval($_time / 1440) ."天前";
        }
    }
    
    //自己空间的通知
    public function set_myself_notice($list){
        foreach ($list as $key=>$val){
            $event_type = $this->bbs_event[$val['event_type']];
            $list[$key]['time_str'] = date("Y-m-d H:i",$val['create_time']);
            $list[$key]['create_time'] = $this->set_time_two($val['create_time']);
            $list[$key]['is_read_for'] = false !== strpos($val['is_read'], $this->bbs_userinfo['user_id']) ? 1 : 0;
            switch ($val['event_type']){
                /**系统方面**/
                case "event_reg"://用户新加入社区欢迎语
                    $list[$key]['content'] = "欢迎你加入&nbsp;<a href='/forum.php' target='_blank' class='font-red'>弹溜溜大院</a>！！";
                    break;
                case "event_add_article"://尊敬的XX：您发表的文章《...》已通过审核，感谢您对弹溜溜的支持，祝您畅游溜溜大院！！
                    $article = $this->db->select("id,title")->from("bbs_article")->where(array("id"=>$val['operator_id']))->order_by("id desc")->get()->row_array();
                    $list[$key]['content'] = "尊敬的<a href='javascript:void;'>@".$this->bbs_userinfo['nickname']."</a>：您发表的文章&nbsp;《<a href='".web_url("p/".encrypt_article_id($val['operator_id']))."' class='font-red' target='_blank'>".$article['title']."</a>》&nbsp;已通过审核，感谢您对弹溜溜的支持，祝您畅游溜溜大院！";
                    break;
                case "event_focus_author"://关注作者
                  $user = $this->db->select("user_id,nickname")->from("users_info")->where(array("user_id"=>$val['user_id']))->order_by("user_id desc")->get()->row_array();
                  $list[$key]['content'] = "<a href='".web_url("u/".encrypt_user_id($user['user_id']))."' class='font-red'>".$user['nickname']."</a>&nbsp;关注了你";
                  break;
                /**文章方面***/
                case "event_like_article"://XX喜欢你的文章XX
                    $user = $this->db->select("user_id,nickname,head_img")->from("users_info")->where(array("user_id"=>$val['user_id']))->order_by("user_id desc")->get()->row_array();
                    $article = $this->db->select("id,title")->from("bbs_article")->where(array("id"=>$val['operator_id']))->order_by("id desc")->get()->row_array();
                    $list[$key]['content'] = "<a href='".web_url("u/".encrypt_user_id($user['user_id']))."' class='font-red'>".$user['nickname']."</a>&nbsp;喜欢了你的文章&nbsp;<a href='".web_url("p/".encrypt_article_id($article['id']))."' class='font-red' target='_blank'>《".$article['title']."》</a>";
                    $list[$key]['head_img'] = $user['head_img'];
                    $list[$key]['nickname'] = $user['nickname'];
                    $list[$key]['space_url'] = web_url("u/".encrypt_user_id($user['user_id']));
                    break;
                case "event_collect_article"://XX收藏了你的文章XX
                    $user = $this->db->select("user_id,nickname,head_img")->from("users_info")->where(array("user_id"=>$val['user_id']))->order_by("user_id desc")->get()->row_array();
                    $article =  $this->db->select("id,title")->from("bbs_article")->where(array("id"=>$val['operator_id']))->order_by("id desc")->get()->row_array();
                    $list[$key]['content'] = "<a href='".web_url("u/".encrypt_user_id($user['user_id']))."' class='font-red'>".$user['nickname']."</a>&nbsp;收藏了您的文章&nbsp;<a href='".web_url("p/".encrypt_article_id($article['id']))."' class='font-red' target='_blank'>《".$article['title']."》</a>";
                    $list[$key]['head_img'] = $user['head_img'];
                    $list[$key]['nickname'] = $user['nickname'];
                    $list[$key]['space_url'] = web_url("u/".encrypt_user_id($user['user_id']));
                    break;
                case "event_comment_article"://评论文章，您在《....》文章中收到了XX的一条新回复。
                    $comment = $this->db->query("select c.id,c.article_id,c.uid,a.title,u.head_img,u.nickname from tan_bbs_article_comment c left join tan_bbs_article a on a.id=c.article_id left join tan_users_info u on u.user_id = c.uid where c.id = ".$val['operator_id']." order by c.id desc limit 1")->row_array();
                    $list[$key]['content'] = "你在文章&nbsp;《<a href='".web_url("p/".encrypt_article_id($comment['article_id']))."' class='font-red' target='_blank'>".$comment['title']."</a>》&nbsp;中收到了&nbsp;<a href='".web_url("u/".encrypt_user_id($comment['uid']))."' class='font-red'>".$comment['nickname']."</a>&nbsp;的一条新回复。<a href='".web_url("p/".encrypt_article_id($comment['article_id'])."/comments/".  encrypt_comment_id($comment['id']))."' class='font-red' target='_blank'>点击查看</a>";
                    $list[$key]['head_img'] = $comment['head_img'];
                    $list[$key]['nickname'] = $comment['nickname'];
                    $list[$key]['space_url'] = web_url("u/".encrypt_user_id($comment['uid']));
                   break;
                case "event_reply_article"://回复评论，您在《....》文章中收到了XX的一条新评论
                    $reply = $this->db->query("select c.id,c.article_id,c.uid,a.title,u.head_img,u.nickname from tan_bbs_article_comment c left join tan_bbs_article a on a.id=c.article_id left join tan_users_info u on u.user_id = c.uid  where c.id = ".$val['operator_id']." order by c.id desc limit 1")->row_array();
                    $list[$key]['content'] = "你在文章&nbsp;《<a href='".web_url("p/".encrypt_article_id($reply['article_id']))."' class='font-red' target='_blank'>".$reply['title']."</a>》&nbsp;中收到了&nbsp;<a href='".web_url("u/".encrypt_user_id($reply['uid']))."' class='font-red'>".$reply['nickname']."</a>&nbsp;的一条新评论。<a href='".web_url("p/".encrypt_article_id($reply['article_id'])."/comments/".encrypt_comment_id($reply['id']))."' class='font-red' target='_blank'>点击查看</a>";
                    $list[$key]['head_img'] = $reply['head_img'];
                    $list[$key]['nickname'] = $reply['nickname'];
                    $list[$key]['space_url'] = web_url("u/".encrypt_user_id($reply['uid']));
                    break;
                case "event_add_article_care"://你关注的好友XX近期发表了一篇文章《》
                    $article = $this->db->query("select a.id,a.title,a.authorid,u.head_img,u.nickname from tan_bbs_article a left join tan_users_info u on u.user_id = a.authorid where a.id = ".$val['operator_id']." order by a.id desc limit 1")->row_array();
                    $list[$key]['content'] = "你关注的好友&nbsp;<a href='".web_url("u/".  encrypt_user_id($article['authorid']))."' class='font-red'>".$article['nickname']."</a>&nbsp;近期发表了一篇文章&nbsp;<a href='".web_url("p/".encrypt_article_id($article['id']))."' class='font-red' target='_blank'>《".$article['title']."》</a>";
                    $list[$key]['head_img'] = $article['head_img'];
                    $list[$key]['nickname'] = $article['nickname'];
                    $list[$key]['space_url'] = web_url("u/".encrypt_user_id($article['authorid']));
                   break;
               
                /**问答相关**/
                case "event_add_wenda_care"://关注的好友近期发布了新的问答
                    $wenda = $this->db->query("select w.id,w.title,i.nickname,i.head_img,i.user_id from tan_bbs_wenda w left join tan_users_info i on i.user_id = w.questioner_id where w.id = ".$val['operator_id']." order by w.id desc limit 1")->row_array();
                    $list[$key]['content'] = "你关注的好友<a href='".web_url("u/".encrypt_user_id($wenda['user_id']))."' class='font-red'>".$wenda['nickname']."</a>&nbsp;近期发布了新的问答&nbsp;<a href='".web_url("wenda/".encrypt_wenda_id($wenda['id']))."' class='font-red'>《".$wenda['title']."》，立即参与>></a>";
                    $list[$key]['head_img'] = $wenda['head_img'];
                    $list[$key]['nickname'] = $wenda['nickname'];
                    $list[$key]['space_url'] = web_url("u/".encrypt_user_id($wenda['user_id']));
                    break;
                case "event_care_answer"://XX关注了你的问答
                    $user = $this->db->select("user_id,nickname,head_img")->from("users_info")->where(array("user_id"=>$val['user_id']))->order_by("user_id desc")->get()->row_array();
                    $wenda = $this->db->query("select w.id,w.title from tan_bbs_wenda w where w.id = ".$val['operator_id']." order by w.id desc limit 1")->row_array();
                    $list[$key]['content'] = "<a href='".web_url("u/".encrypt_user_id($user['user_id']))."' class='font-red'>".$user['nickname']."</a>&nbsp;关注了你的问答&nbsp;<a href='".web_url("wenda/".encrypt_wenda_id($wenda['id']))."' class='font-red'>《".$wenda['title']."》</a>";
                    $list[$key]['head_img'] = $user['head_img'];
                    $list[$key]['nickname'] = $user['nickname'];
                    $list[$key]['space_url'] = web_url("u/".encrypt_user_id($user['user_id']));
                    break;
                case "event_comment_wenda"://你在问答《》中收的了XX的一条新回答
                    $user = $this->db->select("user_id,nickname,head_img")->from("users_info")->where(array("user_id"=>$val['user_id']))->order_by("user_id desc")->get()->row_array();
                    $answer = $this->db->query("select a.id,a.wenda_id,w.title from tan_bbs_wenda_answer a left join tan_bbs_wenda w on w.id = a.wenda_id where a.id = ".$val['operator_id']." order by a.id desc limit 1")->row_array();
                    $list[$key]['content'] = "你在问答&nbsp;<a href='".web_url("wenda/".encrypt_wenda_id($answer['wenda_id']))."' class='font-red'>《".$answer['title']."》</a>&nbsp;收到了&nbsp;<a href='".web_url("u/".encrypt_user_id($user['user_id']))."' class='font-red'>".$user['nickname']."</a>&nbsp;的一条新回答。<a href='".web_url("wenda/".encrypt_wenda_id($answer['wenda_id'])."/answer-".  encrypt_answer_id($answer['id']))."' class='font-red' target='_blank'>点击查看</a>";
                    $list[$key]['head_img'] = $user['head_img'];
                    $list[$key]['nickname'] = $user['nickname'];
                    $list[$key]['space_url'] = web_url("u/".encrypt_user_id($user['user_id']));
                    break;
                case "event_comment_wenda_care"://你关注的问答《》近期有了新的回答。点击查看
                    $answer = $this->db->query("select a.id,a.user_id,a.wenda_id,w.title,u.nickname,u.head_img from tan_bbs_wenda_answer a left join tan_bbs_wenda w on w.id = a.wenda_id left join tan_users_info u on u.user_id = a.user_id where a.id = ".$val['operator_id']." order by a.id desc limit 1")->row_array();
                    $list[$key]['content'] = "你关注的问答&nbsp;<a href='".web_url("wenda/".encrypt_wenda_id($answer['wenda_id']))."' class='font-red'>《".$answer['title']."》</a>&nbsp;近期有了新的回答。<a href='".web_url("wenda/".encrypt_wenda_id($answer['wenda_id'])."/answer-".  encrypt_answer_id($answer['id']))."' class='font-red' target='_blank'>点击查看</a>";
                    $list[$key]['head_img'] = $answer['head_img'];
                    $list[$key]['nickname'] = $answer['nickname'];
                    $list[$key]['space_url'] = web_url("u/".encrypt_user_id($answer['user_id']));
                    break;
                case "event_reply_wenda"://你在问答《》中手打了XX的一条新评论。点击查看
                    $reply = $this->db->query("select r.id,r.answer_id,r.wenda_id,w.title,u.head_img,u.nickname from tan_bbs_wenda_reply r left join tan_bbs_wenda w on w.id = r.wenda_id left join tan_users_info u on u.user_id = r.user_id where r.id = ".$val['operator_id']." order by r.id desc limit 1")->row_array();
                    $list[$key]['content'] = "你在问答&nbsp;<a href='".web_url("wenda/".encrypt_wenda_id($reply['wenda_id']))."' class='font-red'>《".$reply['title']."》</a>&nbsp;中收到了&nbsp;<a href='".  web_url("u/".$reply['user_id'])."'>".$reply['nickname']."</a>&nbsp;的一条新评论。<a href='".web_url("wenda/".encrypt_wenda_id($reply['wenda_id'])."/answer/".  encrypt_answer_id($reply['answer_id'])."/reply-".  encrypt_answer_reply_id($reply['id']))."' class='font-red' target='_blank'>点击查看</a>";
                    $list[$key]['head_img'] = $reply['head_img'];
                    $list[$key]['nickname'] = $reply['nickname'];
                    $list[$key]['space_url'] = web_url("u/".encrypt_user_id($reply['user_id']));
                    break;
                case "event_like_answer"://XX点赞了你在《》中的回答
                    $user = $this->db->select("user_id,nickname,head_img")->from("users_info")->where(array("user_id"=>$val['user_id']))->order_by("user_id desc")->get()->row_array();
                    $answer = $this->db->query("select a.id,a.wenda_id,w.title from tan_bbs_wenda_answer a left join tan_bbs_wenda w on w.id = a.wenda_id where a.id = ".$val['operator_id']." order by a.id desc limit 1")->row_array();
                    $list[$key]['content'] = "<a href='".  web_url("u/".$user['user_id'])."'>".$user['nickname']."</a>&nbsp;点赞了你在&nbsp;<a href='".web_url("wenda/".encrypt_wenda_id($answer['wenda_id'])."/answer-".  encrypt_answer_id($answer['id']))."' class='font-red'>《".$answer['title']."》</a>&nbsp;中的回答。";
                    $list[$key]['head_img'] = $user['head_img'];
                    $list[$key]['nickname'] = $user['nickname'];
                    $list[$key]['space_url'] = web_url("u/".encrypt_user_id($user['user_id']));
                    break;
                case "event_best_answer"://XX采纳了你的回答,点击查看
                    $user = $this->db->select("user_id,nickname,head_img")->from("users_info")->where(array("user_id"=>$val['user_id']))->order_by("user_id desc")->get()->row_array();
                    $answer = $this->db->query("select a.id,a.wenda_id,w.title from tan_bbs_wenda_answer a left join tan_bbs_wenda w on w.id = a.wenda_id where a.id = ".$val['operator_id']." order by a.id desc limit 1")->row_array();
                    $list[$key]['content'] = "<a href='".  web_url("u/".$user['user_id'])."'>".$user['nickname']."</a>&nbsp;采纳了你回答。&nbsp;<a href='".web_url("wenda/".encrypt_wenda_id($answer['wenda_id'])."/answer-".  encrypt_answer_id($answer['id']))."' class='font-red' target='_blank'>点击查看</a>";
                    $list[$key]['head_img'] = $user['head_img'];
                    $list[$key]['nickname'] = $user['nickname'];
                    $list[$key]['space_url'] = web_url("u/".encrypt_user_id($user['user_id']));
                    break;
            }
        }
        return $list;
    }
    //全局系统通知
    public function set_system_notice($list){
        foreach ($list as $key=>$val){
            $event_type = $this->bbs_event[$val['event_type']];
            $time_str = $this->set_time_three($val['create_time']);
            switch ($val['event_type']){
                /**系统方面**/
                case "event_reg"://用户新加入社区欢迎语
                    $user = $this->db->select("user_id,nickname")->from("users_info")->where(array("user_id"=>$val['recieve_id']))->order_by("user_id desc")->get()->row_array();
                    $list[$key]['content'] = "欢迎<a href='".  web_url("u/".encrypt_user_id($val['recieve_id']))."' target='_blank'>@".$user['nickname']."</a>".$time_str."加入<a href='/' target='_blank'>弹溜溜大院</a>！！";
                    break;
                case "event_focus_author"://关注作者
                  $user = $this->db->select("user_id,nickname")->from("users_info")->where(array("user_id"=>$val['user_id']))->order_by("user_id desc")->get()->row_array();
                  $user_ = $this->db->select("user_id,nickname")->from("users_info")->where(array("user_id"=>$val['recieve_id']))->order_by("user_id desc")->get()->row_array();
                  $list[$key]['content'] = "<a href='".web_url("u/".encrypt_user_id($user['user_id']))."'>@".$user['nickname']."</a>".$time_str."关注了"."<a href='".web_url("u/".encrypt_user_id($user_['user_id']))."'>@".$user_['nickname']."</a>";
                  break;
                /**文章方面***/
                case "event_like_article"://XX喜欢XX的文章XX
                    $user = $this->db->select("user_id,nickname,head_img")->from("users_info")->where(array("user_id"=>$val['user_id']))->order_by("user_id desc")->get()->row_array();
                    $article = $this->db->query("select a.id,a.title,a.authorid,i.nickname from tan_bbs_article a left join tan_users_info i on i.user_id = a.authorid where a.id = ".$val['operator_id']." order by a.id desc")->row_array();
                    $list[$key]['content'] = "<a href='".web_url("u/".encrypt_user_id($user['user_id']))."'>@".$user['nickname']."</a>".$time_str."喜欢了<a href='".web_url("u/".encrypt_user_id($article['authorid']))."' target='_blank'>".$article['nickname']."</a>的文章&nbsp;<a href='".web_url("p/".encrypt_article_id($article['id']))."' target='_blank'>《".mb_strcut($article['title'],0,25,"utf-8")."...》</a>";
                    break;
                case "event_collect_article"://XX收藏了XX的文章XX
                    $user = $this->db->select("user_id,nickname,head_img")->from("users_info")->where(array("user_id"=>$val['user_id']))->order_by("user_id desc")->get()->row_array();
                    $article = $this->db->query("select a.id,a.title,a.authorid,i.nickname from tan_bbs_article a left join tan_users_info i on i.user_id = a.authorid where a.id = ".$val['operator_id']." order by a.id desc")->row_array();
                    $list[$key]['content'] = "<a href='".web_url("u/".encrypt_user_id($user['user_id']))."'>@".$user['nickname']."</a>".$time_str."收藏了<a href='".web_url("u/".encrypt_user_id($article['authorid']))."' target='_blank'>".$article['nickname']."</a>的文章<a href='".web_url("p/".encrypt_article_id($article['id']))."' target='_blank'>《".mb_strcut($article['title'],0,25,"utf-8")."...》</a>";
                    break;
                case "event_comment_article"://XX在《...》文章中发表了一条新回复
                    $comment = $this->db->query("select c.id,c.article_id,c.uid,a.title,u.head_img,u.nickname from tan_bbs_article_comment c left join tan_bbs_article a on a.id=c.article_id left join tan_users_info u on u.user_id = c.uid where c.id = ".$val['operator_id']." order by c.id desc limit 1")->row_array();
                    $list[$key]['content'] = "<a href='".web_url("u/".encrypt_user_id($comment['uid']))."' target='_blank'>@".$comment['nickname']."</a>".$time_str."在<a href='".web_url("p/".encrypt_article_id($comment['article_id'])."/comments/".  encrypt_comment_id($comment['id']))."' target='_blank'>《".mb_strcut($comment['title'],0,25,"utf-8")."...》</a>中发表了一条新回复";
                   break;
                case "event_reply_article"://回复评论，您在《....》文章中收到了XX的一条新评论
                    $reply = $this->db->query("select c.id,c.article_id,c.uid,a.title,u.head_img,u.nickname from tan_bbs_article_comment c left join tan_bbs_article a on a.id=c.article_id left join tan_users_info u on u.user_id = c.uid  where c.id = ".$val['operator_id']." order by c.id desc limit 1")->row_array();
                    $list[$key]['content'] = "<a href='".web_url("u/".encrypt_user_id($reply['uid']))."' target='_blank'>@".$reply['nickname']."</a>".$time_str."在<a href='".web_url("p/".encrypt_article_id($reply['article_id'])."/comments/".  encrypt_comment_id($reply['id']))."' target='_blank'>《".mb_strcut($reply['title'],0,25,"utf-8")."...》</a>中发表了一条新评论";
                    break;
                case "event_add_article"://XX近期发表了一篇文章《》
                    $article = $this->db->query("select a.id,a.title,a.authorid,u.head_img,u.nickname from tan_bbs_article a left join tan_users_info u on u.user_id = a.authorid where a.id = ".$val['operator_id']." order by a.id desc limit 1")->row_array();
                    $list[$key]['content'] = "<a href='".web_url("u/".  encrypt_user_id($article['authorid']))."'>@".$article['nickname']."</a>近期发表了一篇文章<a href='".web_url("p/".encrypt_article_id($article['id']))."' target='_blank'>《".mb_strcut($article['title'],0,25,"utf-8")."...》</a>";
                   break;
               
                /**问答相关**/
                case "event_add_wenda"://XX近期发布了新的问答
                    $wenda = $this->db->query("select w.id,w.title,i.nickname,i.head_img,i.user_id from tan_bbs_wenda w left join tan_users_info i on i.user_id = w.questioner_id where w.id = ".$val['operator_id']." order by w.id desc limit 1")->row_array();
                    $list[$key]['content'] = "<a href='".web_url("u/".encrypt_user_id($wenda['user_id']))."' >@".$wenda['nickname']."</a>近期发布了新的问答<a href='".web_url("wenda/".encrypt_wenda_id($wenda['id']))."' class='font-red'>《".mb_strcut($wenda['title'],0,25,"utf-8")."...》</a>";
                    break;
                case "event_care_answer"://XX关注了问答《...》
                    $user = $this->db->select("user_id,nickname,head_img")->from("users_info")->where(array("user_id"=>$val['user_id']))->order_by("user_id desc")->get()->row_array();
                    $wenda = $this->db->query("select w.id,w.title from tan_bbs_wenda w where w.id = ".$val['operator_id']." order by w.id desc limit 1")->row_array();
                    $list[$key]['content'] = "<a href='".web_url("u/".encrypt_user_id($user['user_id']))."'>@".$user['nickname']."</a>".$time_str."关注了问答<a href='".web_url("wenda/".encrypt_wenda_id($wenda['id']))."' target='_blank'>《".mb_strcut($wenda['title'],0,25,"utf-8")."...》</a>";
                    break;
                case "event_comment_wenda"://XX在问答《...》发表了一条新回答
                    $user = $this->db->select("user_id,nickname,head_img")->from("users_info")->where(array("user_id"=>$val['recieve_id']))->order_by("user_id desc")->get()->row_array();
                    $answer = $this->db->query("select a.id,a.wenda_id,w.title from tan_bbs_wenda_answer a left join tan_bbs_wenda w on w.id = a.wenda_id where a.id = ".$val['operator_id']." order by a.id desc limit 1")->row_array();
                    $list[$key]['content'] = "<a href='".web_url("u/".encrypt_user_id($user['user_id']))."'>@".$user['nickname']."</a>".$time_str."在问答<a href='".web_url("wenda/".encrypt_wenda_id($answer['wenda_id'])."/answer-".  encrypt_answer_id($answer['id']))."' target='_blank'>《".mb_strcut($answer['title'],0,25,"utf-8")."...》</a>中发表了一条新回答";
                    break;
                case "event_reply_wenda"://XX在问答《...》中发表了一条新评论
                    $reply = $this->db->query("select r.id,r.answer_id,r.wenda_id,w.title,u.head_img,u.nickname from tan_bbs_wenda_reply r left join tan_bbs_wenda w on w.id = r.wenda_id left join tan_users_info u on u.user_id = r.user_id where r.id = ".$val['operator_id']." order by r.id desc limit 1")->row_array();
                    $list[$key]['content'] = "<a href='".  web_url("u/".encrypt_user_id($reply['user_id']))."'>@".$reply['nickname']."</a>".$time_str."在问答<a href='".web_url("wenda/".encrypt_wenda_id($reply['wenda_id'])."/answer/".  encrypt_answer_id($reply['answer_id'])."/reply-".  encrypt_answer_reply_id($reply['id']))."' target='_blank'>《".mb_strcut($reply['title'],0,25,"utf-8")."...》</a>中发表了一条新评论";
                    break;
                case "event_best_answer"://问答《...》有了最佳答案
                    $answer = $this->db->query("select a.id,a.wenda_id,w.title from tan_bbs_wenda_answer a left join tan_bbs_wenda w on w.id = a.wenda_id where a.id = ".$val['operator_id']." order by a.id desc limit 1")->row_array();
                    $list[$key]['content'] = "问答<a href='".web_url("wenda/".encrypt_wenda_id($answer['wenda_id'])."/answer-".  encrypt_answer_id($answer['id']))."' target='_blank'>《".mb_strcut($answer['title'],0,25,"utf-8")."...》</a>有了最佳答案";
                    break;
            }
        }
        return $list;
    }
    
    function get_next_request_url(){
        $url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
        return "?redirectUrl=".urlencode($url);
    }
    
}